package com.kaiyidiannao.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.kaiyidiannao.activity.SecondHandHouse.SecondHandHouseActivity;
import com.kaiyidiannao.activity.auction.AuctionActivity;
import com.kaiyidiannao.activity.convenience_check.ConvenienceCheck;
import com.kaiyidiannao.activity.daydaycoupon.DdcListActivity;
import com.kaiyidiannao.activity.foodpalace.FoodPalaceActivity;
import com.kaiyidiannao.activity.messageInfo.MessageInfo;
import com.kaiyidiannao.activity.secondhandcar.SecondHandCarActivity;
import com.kaiyidiannao.main.R;

/**
 * Created by 闯儿 on 14-4-1.
 */
public class HomeFragment extends Fragment implements View.OnClickListener {
    public static final String TAG = "HomeFragment";
    private View rootView;

    // 10个模块的RelativeLayout布局
    private View auctionLinearLayout;
    private View daydaycouponLinearLayout;
    private View tourLinearLayout;
    private View foodPalace;
    private View buyStreet;
    private View secondHandHouse;
    private View palyHappyHouse;
    private View secondHandCar;
    private View convenienceCheck;
    private View messageInfo;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        rootView = getActivity().getLayoutInflater().inflate(R.layout.home_main, null);
        init();
    }

    private void init() {
        auctionLinearLayout = rootView.findViewById(R.id.home_main_auction);
        auctionLinearLayout.setOnClickListener(this);

        daydaycouponLinearLayout =  rootView.findViewById(R.id.home_main_daydaycoupon);
        daydaycouponLinearLayout.setOnClickListener(this);

        tourLinearLayout =  rootView.findViewById(R.id.home_main_tour);
        tourLinearLayout.setOnClickListener(this);

        foodPalace =  rootView.findViewById(R.id.foodPalace);
        foodPalace.setOnClickListener(this);

        secondHandHouse =  rootView.findViewById(R.id.secondHandHouse);
        secondHandHouse.setOnClickListener(this);

        secondHandCar = rootView.findViewById(R.id.secondUserdCars);
        secondHandCar.setOnClickListener(this);

        buyStreet = rootView.findViewById(R.id.buyStreet);
        buyStreet.setOnClickListener(this);

        palyHappyHouse = rootView.findViewById(R.id.palyHanppyHouse);
        palyHappyHouse.setOnClickListener(this);

        messageInfo = rootView.findViewById(R.id.messageInfo);
        messageInfo.setOnClickListener(this);

        convenienceCheck =  rootView.findViewById(R.id.convenienceCheck);
        convenienceCheck.setOnClickListener(this);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        if (rootView != null && rootView.getParent() != null) {
            View oldParent = (View) rootView.getParent();
            if (oldParent != container) {
                ((ViewGroup) oldParent).removeView(rootView);
            }
        }
        return rootView;
    }

    @Override
    public void onClick(View v) {
        Class<?> classz = null;
        int module_type = 0;
        switch (v.getId()) {
            case R.id.home_main_auction: //拍拍乐
                classz = AuctionActivity.class;
                break;
            case R.id.home_main_daydaycoupon://天天惠
                module_type = DdcListActivity.MODULE_DAY_DAY_COUPON;
                classz = DdcListActivity.class;
                break;
            case R.id.home_main_tour: //凑队去
                module_type = DdcListActivity.MODLUE_TOUR;
                classz = DdcListActivity.class;
                break;
            case R.id.foodPalace://美食城
                module_type = FoodPalaceActivity.MODULE_FOOD_PALACE;
                classz = FoodPalaceActivity.class;
                break;
            case R.id.buyStreet://购物街 - 十字街
                module_type = FoodPalaceActivity.MODLUE_BUY_STREET;
                classz = FoodPalaceActivity.class;
                break;
            case R.id.palyHanppyHouse: //玩乐住
                module_type = FoodPalaceActivity.MODLUE_PLAY;
                classz = FoodPalaceActivity.class;
                break;
            case R.id.secondHandHouse: //二手房
                classz = SecondHandHouseActivity.class;
                break;
            case R.id.secondUserdCars://二手车
                classz = SecondHandCarActivity.class;
                break;
            case R.id.messageInfo://信息框
                classz = MessageInfo.class;
                break;
            case R.id.convenienceCheck: //便民查
                classz = ConvenienceCheck.class;
                break;
        }
        Intent intent = new Intent(getActivity(), classz);
        intent.putExtra("module_type", module_type);
        startActivity(intent);
    }
}
